#pragma region Licensing
/*
       LOGL::GLib -> LorgonJortle's OpenGL Game Library
       Copyright (C) 2011  Jesse 'LorgonJortle' Wilkerson

       This program is free software: you can redistribute it and/or modify
       it under the terms of the GNU General Public License as published by
       the Free Software Foundation, either version 3 of the License, or
       (at your option) any later version.

       This program is distributed in the hope that it will be useful,
       but WITHOUT ANY WARRANTY; without even the implied warranty of
       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       GNU General Public License for more details.

       You should have received a copy of the GNU General Public License
       along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#pragma endregion

#include "Font.h"

namespace LOGL_GLib
{
     namespace Common
     {
          /* Initialize our static ID counter. */
          GLuint Font::idCounter = 0;

          /******************************************************************************
           Font::Font();
                    Arguments:
                         void

                    Description:
                         Constructs a Font object.

                    Returns:
                         The Font object.
          *******************************************************************************/
          Font::Font()
          {
               /* Set some defaults. */
               TypeFace = 0;
               size = 12;
               id = ++idCounter;
          }

          /******************************************************************************
           Font::~Font();
                    Arguments:
                         void

                    Description:
                         Destructs the Font object, releasing any indebted resources.

                    Returns:
                         void
          *******************************************************************************/
          Font::~Font()
          {
               if (TypeFace != 0)
                    TTF_CloseFont(TypeFace);
          }

          /******************************************************************************
           GLboolean Font::Load(const std::string& _File, GLuint _Size);
                    Arguments:
                         const std::string& _File:
                              The location of the typeface file to load.
                         GLuint _Size:
                              The size to load the font as.

                    Description:
                         Loads the specified font with the specified size.

                    Returns:
                         Whether or not the font successfully loaded.
          *******************************************************************************/
          GLboolean Font::Load(const std::string& _File, GLuint _Size)
          {
               /* Clear the font if it was previously loaded. */
               if(TypeFace != 0)
                    TTF_CloseFont(TypeFace);
               TypeFace = 0;

               /* Attempt to load the font. */
               TypeFace = TTF_OpenFont(_File.c_str(), _Size);

               /* Return whether or not the load succeded. */
               return (TypeFace != 0);
          }

          /******************************************************************************
           GLint Font::Height();
                    Arguments:
                         void

                    Description:
                         Gets the maximum height of the font.

                    Returns:
                         The maximum height of the font.
          *******************************************************************************/
          GLint Font::Height()
          {
               return TTF_FontHeight(TypeFace);
          }

          /******************************************************************************
           GLint Font::TextWidth(const std::string& _Text);
                    Arguments:
                         const std::string& _Text:
                              A string to calculate the width of.

                    Description:
                         Calculates the width of the specified string with this font.

                    Returns:
                         The width of the specified string rendered with this font.
          *******************************************************************************/
          GLint Font::TextWidth(const std::string& _Text)
          {
               GLint width, height;
               TTF_SizeText(TypeFace, _Text.c_str(), &width, &height);

               return width;
          }

     } /* Namespace Common. */
} /* Namespace LOGL_GLib. */
